//
//  CZVisitorTableViewController.swift
//  Weibo28
//
//  Created by Apple on 16/5/11.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZVisitorTableViewController: UITableViewController {
    //  用户是否登录的标记
    var userLogin = CZUserAccountViewModel.sharedUserAccount.isLogin
    
    //  访客视图
    var visitorView: CZVisitorView?
    
    override func loadView() {
        if userLogin {
            super.loadView()
        } else {
            //  没有登录的情况下,我们需要提供自定义的访客视图
            visitorView = CZVisitorView()
            //
            visitorView!.callBackClosure = { [weak self] in
                print("哈哈")
                print(self)
                self?.requestOAuthLogin()
            }
            
            view = visitorView
            
            //  创建按钮
            setupNavUI()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    //  设置导航栏按钮
    private func setupNavUI() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", fontSize: 15, target: self, action: "registerAction")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", fontSize: 15, target: self, action: "loginAction")

    }
    
    //  MARK:   - 点击事件
    
    @objc private func registerAction() {
        print("registerAction")
        requestOAuthLogin()
    }
    
    
    @objc private func loginAction() {
        print("loginAction")
        requestOAuthLogin()
    }
    
    private func requestOAuthLogin() {
        let oauthVC = CZOAuthViewController()
        let nav = UINavigationController(rootViewController: oauthVC)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
    
    
    
    
    
    

}
